package com.uchiha.nova.mainService.wrapper;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.uchiha.nova.core.model.entity.UserEntity;
import com.uchiha.nova.core.tool.support.BaseEntityWrapper;
import com.uchiha.nova.core.tool.node.ForestNodeMerger;
import com.uchiha.nova.core.model.entity.TenantUserEntity;
import com.uchiha.nova.core.model.vo.TenantUserVO;
import com.uchiha.nova.mainService.service.ITenantUserService;
import com.uchiha.nova.core.tool.util.SpringUtil;
import com.uchiha.nova.mainService.service.UserRoleService;
import com.uchiha.nova.mainService.service.UserService;

import java.util.List;
import java.util.stream.Collectors;
/**
 * 租户用户信息 包装类,返回视图层所需的字段
 *
 * @author Uchihashiamu
 */
public class TenantUserWrapper extends BaseEntityWrapper<TenantUserEntity, TenantUserVO>  {

	ITenantUserService tenantUserService = SpringUtil.getBean(ITenantUserService.class);

	UserService userService = SpringUtil.getBean(UserService.class);
	UserRoleService userRoleService = SpringUtil.getBean(UserRoleService.class);


	public static TenantUserWrapper build() {
		return new TenantUserWrapper();
	}

	@Override
	public TenantUserVO entityVO(TenantUserEntity tenantUserEntity) {
		TenantUserVO tenantUserVO = new TenantUserVO();
		BeanUtil.copyProperties(tenantUserEntity, tenantUserVO);

		return tenantUserVO;
	}
	public List<TenantUserVO> listVO(List<TenantUserEntity> list) {
		List<TenantUserVO> collect = list.stream().map(item -> {
			TenantUserVO tenantUserVO = new TenantUserVO();
			BeanUtil.copyProperties(item, tenantUserVO);
			return tenantUserVO;
		}).collect(Collectors.toList());
		return collect;
		// return ForestNodeMerger.merge(collect);
	}

	@Override
	public IPage<TenantUserVO> pageVO(IPage<TenantUserEntity> pages) {
		IPage<TenantUserVO> page = pages.convert(item->{
			TenantUserVO tenantUserVO = new TenantUserVO();
			BeanUtil.copyProperties(item, tenantUserVO);
			UserEntity userEntity = userService.getById(tenantUserVO.getId());
			tenantUserVO.setImg(userEntity.getAvatar());
			return tenantUserVO;
		});
		return page;
	}
}
